package com.longdaji.decoration.ui.creditassess;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.longdaji.decoration.R;
import com.longdaji.decoration.base.BaseActivity;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by longtao on 2017/12/19.
 */

public class CreditAssessActivity extends BaseActivity implements CreditAssessContract.View {

    private static final String TAG = CreditAssessActivity.class.getSimpleName();
    @BindView(R.id.tv_title)
    TextView mTvTitle;
    @BindView(R.id.et_name)
    EditText mEtName;
    @BindView(R.id.et_card_num)
    EditText mEtCardNum;
    @Inject
    CreditAssessPresenter mPresenter;

    public static Intent getStartIntent(Context context) {
        Intent intent = new Intent(context, CreditAssessActivity.class);
        return intent;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.d(TAG, "CreditAssessActivity onCreate");
        setContentView(R.layout.activity_credit_assess);
        setUnBinder(ButterKnife.bind(this));
        initView();
    }

    private void initView() {
        mPresenter.setView(this);
        mTvTitle.setText("芝麻信用评估");
    }

    @Override
    protected void onDestroy() {
        mPresenter.detachView();
        super.onDestroy();
    }

    @OnClick({R.id.iv_back,R.id.btn_taobao_next})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                finish();
                break;
            case R.id.btn_taobao_next:
                mPresenter.verifyCreditScore(mEtCardNum.getText().toString(), mEtName.getText().toString());
                break;
            default:
                break;
        }
    }

    @Override
    public void showVerifySuccess() {
        Intent intent = new Intent();
        intent.putExtra("verify_result", true);
        setResult(RESULT_OK, intent);
        finish();
    }

    @Override
    public void showVerifyFail() {
        Intent intent = new Intent();
        intent.putExtra("verify_result", false);
        setResult(RESULT_OK, intent);
        finish();
    }
}
